<?php

class BreadthFirstTraversal implements TreeTraversable 
{
    function traverseTree(BinaryTreeNode $node) 
    {
		if($node == null){
			return array();
		}
		
		$nodeQueue = new Queue();
		
		$nodeQueue->enqueue($node);
		
		while (!$nodeQueue->isEmpty()) {
    		
    		$traversalNode = $nodeQueue->dequeue();
			
			$this->_data[] = $traversalNode->getValue();
			
			if($traversalNode->getLeft() != null){
				$nodeQueue->enqueue($traversalNode->getLeft());
			}
			
			if($traversalNode->getRight() != null){
				$nodeQueue->enqueue($traversalNode->getRight());
			}
		}
		
		return $this->_data;
    }
}
?>